<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /*
     2.beforeunload()事件
         - 会在windows上触发,用意是给开发者提供阻止页面被卸载的机会
         - mac上试了下好像不行
  */
    window.addEventListener("beforeunload", (event) => {
        let message = "I'm really going to miss you if you go.";
        event.returnValue = message;
        return message;
    });
</script>
</body>
</html>